//
//  ST_TicketTipViewController.swift
//  btvideo
//
//  Created by Jason on 2021/12/2.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import UIKit
import SwiftUI

class ST_TicketTipViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        make_u_i()
        setScroll()
    }
    
    @objc func goBack() {
        self.goback_previous_controller()
    }
    
    fileprivate func make_u_i() {
        view.addSubviews([scrollView, back_button])
        scrollView.addSubviews([whiteView, title_image_view])
        
        scrollView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        whiteView.snp.makeConstraints { make in
            make.left.right.equalTo(self.view)
            make.top.equalToSuperview()
            make.height.equalTo(36 + statusBarHeight)
        }
        
        title_image_view.snp.makeConstraints { make in
            make.left.equalTo(self.view).offset(TIANCompatibleValue(value: 28))
            make.right.equalTo(self.view).offset(-(TIANCompatibleValue(value: 27)))
            make.top.equalTo(whiteView.snp.bottom)
            make.height.equalTo(TIANCompatibleValue(value: 53))
        }
        
        back_button.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(5)
            make.top.equalToSuperview().offset(10 + statusBarHeight)
            make.size.equalTo(CGSize(width: 50, height: 50))
        }
    }
    
    fileprivate func setScroll() {
        var last: UIImageView?
        for index in 0...5 {
            let imageView = create_image_view(index: index)
            scrollView.addSubview(imageView)
            
            imageView.snp.makeConstraints { make in
                make.left.right.equalTo(self.view)
                if index == 0 {
                    make.top.equalTo(title_image_view.snp.bottom).offset(24)
                }else {
                    if let view = last {
                        make.top.equalTo(view.snp.bottom)
                    }
                }
                if index == 5 {
                    make.bottom.equalToSuperview()
                }
                switch index {
                case 0, 1, 2:
                    make.height.equalTo(TIANCompatibleValue(value: 546))
                case 3:
                    make.height.equalTo(TIANCompatibleValue(value: 570))
                case 4:
                    make.height.equalTo(TIANCompatibleValue(value: 624))
                case 5:
                    make.height.equalTo(TIANCompatibleValue(value: 572))
                default:
                    break
                }
            }
            
            last = imageView
        }
    }
    
    fileprivate func create_image_view(index: Int) -> UIImageView {
        let imageView = UIImageView()
        switch index {
        case 0:
            imageView.image = ST_ImageUtils.imageName("ticket_help_1")
        case 1:
            imageView.image = ST_ImageUtils.imageName("ticket_help_2")
        case 2:
            imageView.image = ST_ImageUtils.imageName("ticket_help_3")
        case 3:
            imageView.image = ST_ImageUtils.imageName("ticket_help_4")
        case 4:
            imageView.image = ST_ImageUtils.imageName("ticket_help_5")
        case 5:
            imageView.image = ST_ImageUtils.imageName("ticket_help_6")
        default:
            break
        }
        return imageView
    }

    // MARK: - UI
    fileprivate lazy var scrollView: UIScrollView = {
        let s = UIScrollView()
        s.backgroundColor = .white
        return s
    }()
    
    fileprivate lazy var whiteView: UIView = {
        let v = UIView()
        v.backgroundColor = .white
        return v
    }()
    
    fileprivate lazy var title_image_view: UIImageView = {
        let i = UIImageView()
        i.image = ST_ImageUtils.imageName("ticket_title")
        return i
    }()
    
    fileprivate lazy var back_button: UIButton = {
        let b = UIButton()
        b.setImageForAllStates(ST_ImageUtils.imageName("ticket_back") ?? UIImage())
        b.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
        b.addTarget(self, action: #selector(goBack), for: .touchUpInside)
        return b
    }()
}
